<%@ page import="org.json.simple.*" %> <%--json_simple_1-1.jar--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    import = "java.sql.*"
	%>
<%
	request.setCharacterEncoding("UTF-8");
	
	String url = "jdbc:oracle:thin:@155.230.193.42:1521:oraknu";
	String user = "system";
	String pass = "DBLab012345";
	Connection con = null;
	String sql = null;
	int result;
	JSONObject resultJson = new JSONObject();

	String obj = request.getParameter("article_num");
	int articleNumber = Integer.parseInt(obj);
	
	String id = (String) session.getAttribute("logID");
	try
	{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("success");
	}
	catch(ClassNotFoundException e)
	{
		System.err.println("error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con = DriverManager.getConnection(url, user, pass);
	}
	catch(SQLException e)
	{
		System.err.println("sql error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con.setAutoCommit(false);
		
		sql = "select aid, to_char(pubdate, 'yyyy:mm:dd hh:mi:ss') as pdate, contents, title from article where aid = ?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setInt(1, articleNumber);

		ResultSet rs = pstmt.executeQuery();
		if(rs.next())
		{
			String cont = rs.getString("contents").replace("\\", "\\\\").replace("\'", "\\\'").replace("\"", "\\\"").replace("\r\n", "\\n").replace("\n", "\\n");
			String title = rs.getString("title").replace("\\", "\\\\").replace("\'", "\\\'").replace("\"", "\\\"").replace("\r\n", "\\n").replace("\n", "\\n");

			resultJson.put("aid", rs.getInt("aid"));
			resultJson.put("pubtime", rs.getString("pdate"));
			resultJson.put("cont", cont);
			resultJson.put("title", title);
		}
		pstmt.close();
		con.close();
	}
	catch(Exception e)
	{
		System.err.println("sql error = " + e.getMessage());
	}
	out.print(resultJson);	
%>